package com.matt.controller.pad;

import com.matt.domain.WorkPlace;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.commons.model.StatusResponse;
import com.matt.commons.page.PagerQuery;
import com.matt.service.remoteCall.SsoCallService;
import com.matt.service.WorkPlaceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.matt.foundation.constant.RequestConstant.*;


@RestController
@RequestMapping("/pad/workPlace")
@Slf4j
public class PadWorkPlaceController {

    @Autowired
    private WorkPlaceService workPlaceService;

    @Autowired
    private MemVerificationCache cache;

    @Autowired
    private SsoCallService ssoCallService;

    @Value("${workplace.default.appid}")
    private String defaultAppId;

    @RequestMapping("/getWorkPlaceList")
    public StatusResponse getWorkPlaceList(@RequestHeader(value = API_VERSION, required = false) Integer apiVersion,
                                           @RequestHeader(value = APP_ID, required = false) String appid,
                                           @RequestHeader(TICKET) String ticket,
                                           String  roleCode, PagerQuery query){
        String areaId = cache.getAreaId(ticket);
        String staffId = cache.getStaffId(ticket);
        if(StringUtils.isBlank(appid)){
            appid = defaultAppId;
        }
        Page<WorkPlace> recordPage = workPlaceService.getWorkPlaceList(areaId,staffId,roleCode, apiVersion, appid, query.getPageNum(), query.getPageSize());
        return StatusResponse.success(recordPage);
    }



}
